{include file="public/header" /}
<span class="layui-breadcrumb">
  <a href="{:url('Classpay/index')}?nav=blog-bloglist">购买分类</a>
  <a><cite>{if !empty($data_list['id']) }编辑{else/}添加{/if}购买分类</cite></a>
</span>
<div class="layui-fluid">
    <div class="layui-card">
      <div class="layui-card-body">
        <div style="color:#FF5722">{if !empty($data_list['id']) }编辑{else/}添加{/if}购买分类,返回页面后请刷新</div>
        <div class="layui-form">
         <form class="layui-form" action="" style='padding:10px;'>
          <div class="layui-form-item">
            <label class="layui-form-label">分类名</label>
            <div class="layui-input-block">
                <input type="text" name="cname" value="{if !empty($data_list['cname']) }{$data_list['cname']}{/if}" autocomplete="off" placeholder="请输入分类名" class="layui-input">
            </div>
          </div>
          <div class="layui-form-item">
            <label class="layui-form-label">url</label>
            <div class="layui-input-block">
                <input type="text" name="url" value="{if !empty($data_list['url']) }{$data_list['url']}{/if}" autocomplete="off" placeholder="请输入url" class="layui-input">
            </div>
          </div>
             <div class="layui-form-item">
                 <label class="layui-form-label">排序</label>
                 <div class="layui-input-block">
                     <input type="text" name="seq" value="{if !empty($data_list['seq']) }{$data_list['seq']}{/if}" autocomplete="off" placeholder="请输入排序" class="layui-input">
                 </div>
             </div>


          <div class="layui-form-item">
            <label class="layui-form-label"></label>
            <div class="layui-input-block">
              <button type="button" class="layui-btn layui-btn-sm" onclick="insert_edit({if !empty($data_list['id']) }{$data_list['id']}{else/}'tj'{/if})">确 定</button>
            </div>
          </div>
          
        </form>

        </div>
      </div>  
    </div>
</div>
{include file="/public/footer" /}

<script>
    layui.use('upload', function(){
        var $ = layui.jquery
            ,upload = layui.upload;

        //普通图片上传
        var uploadInst = upload.render({
            elem: '#upload_img'
            ,accept: 'file'
            ,url: "{:url('index/Oos/upload_blog_img')}" //改成您自己的上传接口
            ,before: function(obj){
                //预读本地文件示例，不支持ie8
                obj.preview(function(index, file, result){
                    $('#show_img').attr('src', result); //图片链接（base64）
                });
            }
            ,done: function(res){
                //如果上传失败
                if(res.status == '0'){
                    return layer.msg(res.msg);
                }else{ //上传成功
                    $("input[name='newname']").val(res.newname);
                    return layer.msg(res.msg);
                }
            }
            ,error: function(){
                //演示失败状态，并实现重传
                var demoText = $('#demoText');
                demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
                demoText.find('.demo-reload').on('click', function(){
                    uploadInst.upload();
                });
            }
        });
    });
</script>
<script charset="utf-8" src="/static/kindeditor/kindeditor-all.js"></script>
<script charset="utf-8" src="/static/kindeditor/lang/zh-CN.js"></script>
<script>
    KindEditor.ready(function(K) {
        window.editor=K.create('#content',{'items':['source', '|', 'undo', 'redo', '|','selectall', 'preview', 'print', 'code', 'cut', 'copy', 'paste','plainpaste', 'wordpaste', '|', 'justifyleft', 'justifycenter', 'justifyright','justifyfull', 'insertorderedlist', 'insertunorderedlist', 'indent', 'outdent', 'subscript','superscript', 'clearhtml', 'quickformat', '|','formatblock', 'fontname', 'fontsize', '|', 'forecolor', 'hilitecolor', 'bold','italic', 'underline', 'strikethrough', 'lineheight', 'removeformat', '|', 'image', 'media', 'insertfile', 'table', 'hr', 'emoticons', 'baidumap', 'pagebreak','anchor', 'link', 'unlink','|', 'fullscreen'],'uploadJson':"{:url('index/Oos/upload_blog')}",afterCreate : function() { this.sync(); },afterBlur: function(){this.sync();}
        });

    })


  function insert_edit(id){
      layer.load();
      var cname=$.trim($("input[name='cname']").val());
      var url1=$.trim($("input[name='url']").val());
      var seq=$.trim($("input[name='seq']").val());
      
      if(cname==''){
          layer.closeAll('loading');
          layer.msg('请填写分类名');
          return false;
      }
      if(url1==''){
          layer.closeAll('loading');
          layer.msg('请填写url');
          return false;
      }



      if(id=='tj'){
        var url="{:url('Classpay/do_change')}";
      }else{
        var url="{:url('Classpay/do_change')}"+"?id="+id;
      }
      $.post(url,{cname:cname,url1:url1,seq:seq},function(res){
        if(res.status=='0'){
            layer.closeAll('loading');
            layer.msg(res.msg);
        }
        if(res.status=='1'){
            layer.msg(
            res.msg,{time: 1500 },
            function(){
              layer.closeAll();
              location.href=location.href;
            });
        }
    }) 
  }
</script>


